Support broadcasting matmul in col-major layout#81
Merged
Conversation
Replace the col-major branch of `LayoutMatMulConfig::layout_matmul`
(which rejected rules 3-7) with a thin wrapper that delegates to the
row-major routine via the identity
C[t, m, n] = A[t, m, k] @ B[t, k, n] (row-major)
<=> C[n, m, t] = B[n, k, t] @ A[k, m, t] (col-major)
i.e. reverse all axes and swap A/B. The returned layouts are reversed
and the A/B fields are swapped back so callers see the original operand
order.
This brings full broadcasting (rules 3-7) to col-major for free,
matching the convention that `DeviceMatMulAPI` impls already use
(see e.g. `device_faer/matmul.rs`, which reverses axes and swaps A/B
before dispatching to the row-major kernel).
Also:
- Update the module-level docs to describe the col-major convention
(matmul dims are the first two; trailing dims broadcast).
- Replace the test that asserted col-major broadcasting fails with
positive tests covering rules 3, 4 and 7 (incl. a `1` broadcast).
- Update the device_faer matmul test to exercise col-major broadcasting
end-to-end via `set_default_order(ColMajor)`.
Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: glm-5.1 <service@zhipuai.cn>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements broadcasting of matmul in column-major.
This is enhancement, but also considered as behavior change.
Broadcasting matmul is allowed in NumPy and many similar row-major frameworks, but disallowed in Julia and similar col-major tensor frameworks. This PR decides to support NumPy-like matmul broadcasting, but in col-major.